package com.siemens.industrial.app;

import java.io.*;

/**
 * Created by qupen on 2016/9/23.
 */
public class Logger {
    public static boolean logToFile(String logPath, String logName, String log, boolean append) {
        try {
            File logDir = new File(logPath);
            if (!logDir.exists() && !logDir.isDirectory()) {
                logDir.mkdirs();
            }

            File logFile = new File(logPath + "/" + logName);

            if (!logFile.exists()) {
                logFile.createNewFile();
            }

            FileWriter fileWriter = new FileWriter(logFile, append);
            BufferedWriter bufferWriter = new BufferedWriter(fileWriter);
            bufferWriter.write(log + "\r\n");
            bufferWriter.close();

            return true;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return false;
    }
}
